package com.zuorenke.db.extend;

/**
 * @author Z.R.K
 * @description
 * @create 2019-04-12 15:56:04
 **/
public class MySQLDialect extends Dialect {
	
	@Override
	public boolean supportsLimitOffset() {
		return true;
	}
	
	@Override
	public boolean supportsLimit() {
		return true;
	}
	
	@Override
	public String getLimitString(String sql, int offset, int limit) {
		StringBuilder sb = new StringBuilder(sql.length() + 20);
		sb.append(sql);
		sb.append(" limit ");
		if (offset > 0) {
			sb.append(offset);
			sb.append(",");
		}
		sb.append(limit);
		return sb.toString();
	}
	
	@Override
	public String getCountSql(String sql) {
		StringBuilder sb = new StringBuilder(sql.length() + 40);
		sb.append("SELECT count(*) FROM (");
		sb.append(sql);
		sb.append(") table_count");
		return sb.toString();
	}
}